package ext.tianma.project.relatedproduct;

import java.rmi.RemoteException;
import java.util.List;

import wt.inf.container.WTContainer;
import wt.projmgmt.admin.Project2;
import wt.util.WTException;

import com.ptc.core.components.beans.ObjectBean;
import com.ptc.core.components.forms.FormResult;
import com.ptc.netmarkets.project.processor.CreatePROPLProjectFormProcessor;
import com.ptc.netmarkets.util.beans.NmCommandBean;

import ext.tianma.bom.workflow.ExamineAndApproveConfirmBusiness;

/**Description: 创建项目的prcessor
 * @author    :  YangWen
 * @create at :  2013-8-19   上午11:00:00
 */
public class CreateProjectFormProcessor extends CreatePROPLProjectFormProcessor {
	
	public FormResult doOperation(NmCommandBean paramNmCommandBean, List<ObjectBean> paramList) throws WTException {
					
		 FormResult result = super.doOperation(paramNmCommandBean, paramList);
		 
		 WTContainer localWTContainer = getContainerFromObjectBeans(paramList);		 
		 Project2 project = (Project2)localWTContainer;
		 String partRFQNumber = null;
		 try {
			//RFQ编号   partRFQNumber   等同于【RFQ文档】的名称，不是编号 ，匹配则读取，不匹配就读；
			Object obj = ext.com.iba.IBAUtil.getIBAValue(project , "partRFQNumber");
			if(obj != null || obj instanceof String)
				partRFQNumber = (String) obj;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		 
		 if(ExamineAndApproveConfirmBusiness.isObjectType(project, ".ConsumptionProject"))
			 CreateProjectBusiness.setAttribution(project, partRFQNumber);
		 
		 return result;
	}
	
		
	
	 private WTContainer getContainerFromObjectBeans(List<ObjectBean> paramList) throws WTException {
		    WTContainer localWTContainer = null;
		    ObjectBean localObjectBean = getObjectBeanByType(paramList, WTContainer.class);
		    if (localObjectBean != null) {
		      localWTContainer = (WTContainer)localObjectBean.getObject();
		    }
		    if (localWTContainer == null) {
		      throw new WTException(getContainerType() + " not created: no WTContainer object found in the ObjectBean list");
		    }
		    return localWTContainer;
	 }

}
